package com.ruoyi.web.controller.gxs;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gxs.domain.GxsComprehensive;
import com.ruoyi.gxs.service.IGxsComprehensiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 我的综合得分Controller
 * 
 * @author 高晓松
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/gxs/MyComprehensive")
public class GxsComprehensiveController extends BaseController
{
    @Autowired
    private IGxsComprehensiveService gxsComprehensiveService;

    /**
     * 查询综合得分列表
     */
//    @PreAuthorize("@ss.hasPermi('gxs:MyComprehensive:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxsComprehensive gxsComprehensive)
    {
        startPage();
        List<GxsComprehensive> list = gxsComprehensiveService.selectGxsComprehensiveList(gxsComprehensive);
        return getDataTable(list);
    }

    /**
     * 导出综合得分列表
     */
//    @PreAuthorize("@ss.hasPermi('gxs:MyComprehensive:export')")
    @Log(title = "我的综合得分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxsComprehensive gxsComprehensive)
    {
        List<GxsComprehensive> list = gxsComprehensiveService.selectGxsComprehensiveList(gxsComprehensive);
        ExcelUtil<GxsComprehensive> util = new ExcelUtil<GxsComprehensive>(GxsComprehensive.class);
        util.exportExcel(response, list, "我的综合得分数据");
    }

    /**
     * 获取综合得分详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gxs:MyComprehensive:query')")
    @GetMapping(value = "/{gxsAppraisalid}")
    public AjaxResult getInfo(@PathVariable("gxsAppraisalid") Long gxsAppraisalid)
    {
        return success(gxsComprehensiveService.selectGxsComprehensiveByGxsAppraisalid(gxsAppraisalid));
    }

    /**
     * 新增综合得分
     */
//    @PreAuthorize("@ss.hasPermi('gxs:MyComprehensive:add')")
    @Log(title = "我的综合得分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxsComprehensive gxsComprehensive)
    {
        return toAjax(gxsComprehensiveService.insertGxsComprehensive(gxsComprehensive));
    }

    /**
     * 修改综合得分
     */
//    @PreAuthorize("@ss.hasPermi('gxs:MyComprehensive:edit')")
    @Log(title = "我的综合得分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxsComprehensive gxsComprehensive)
    {
        return toAjax(gxsComprehensiveService.updateGxsComprehensive(gxsComprehensive));
    }

    /**
     * 删除综合得分
     */
//    @PreAuthorize("@ss.hasPermi('gxs:MyComprehensive:remove')")
    @Log(title = "我的综合得分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gxsAppraisalids}")
    public AjaxResult remove(@PathVariable Long[] gxsAppraisalids)
    {
        return toAjax(gxsComprehensiveService.deleteGxsComprehensiveByGxsAppraisalids(gxsAppraisalids));
    }

    /**
     * 查询我的综合得分列表
     */
    //    @PreAuthorize("@ss.hasPermi('gxs:MyComprehensive:list')")
    @GetMapping("/MyList")
    public TableDataInfo MyList(GxsComprehensive gxsComprehensive)
    {
        startPage();
        List<GxsComprehensive> list = gxsComprehensiveService.selectGxsComprehensiveList(gxsComprehensive);

        String username = getUsername();

        for (int i = 0 ; i < list.size(); i++){
            String userName = list.get(i).getUserName();
            if (!userName.equals(username)) {
                list.remove(i);

                System.out.println(true);
                i--;
            }

        }
        return getDataTable(list);
    }
}
